package com.iyue.util.security;

import java.security.MessageDigest;

public class MD5
{
	public static String getMD5ofStr(String s)
	{
		if(s == null) return null;
		try{
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] result = md.digest(s.getBytes());

			StringBuffer buff = new StringBuffer();
			for(int i = 0; i < result.length; i++){
	  		String byteStr = Integer.toHexString(result[i] & 0xFF);
	  		if(byteStr.length() < 2)
	  			buff.append('0');
	  			buff.append(byteStr);
			}
			
			return buff.toString();
		
		}catch (Exception e){
			return null;
		}
	}
	
	public static void main(String[] args)
	{
	// TODO Auto-generated method stub
		
		String str = getMD5ofStr("appadmin");
		System.out.println("md5str is " + str);
	}
}